// index.js
import Toast from '../../miniprogram/miniprogram_npm/@vant/weapp/toast/toast';
const request = require('../../util/request')
Page({
    data: {
        // navBarHeight: navBarHeight,
        customer: {},
        projects: [],
        activeTab: 0,
        account: {},
        all: [],
        tabIndex: 0,
        roleslist:["","超级管理员","管理员","生产负责人","质检员","操作工"],
        user_roles:"",
        accounts: [],
        selstart:0,//初始默认选中待办事项1
        userinfo:{
          // name:"崔贺",work:"经理",group:"it",root:"1"
        },
        //质检通知
        worklist:[],
        data1:[],
        data2:[],
        data3:[],
        data4:[],
        data5:[],
        connState: false,
        searchState: false,
        connDevice: '',
        connectInit: false,
        WH: [0, 0],
        system: '',
        textarea: '',
        serviceId: '',
        blueLists: [],
        deviceId: '',
        imageSize: [0, 0],
        notify: "2700c46ba143131981af816414cdbf4b2c88e4664978cbfd33e7ff0073d7714ad1c0d2c4c049fcb7f5", // 返回信号
        hasLoadPic: false,
        get_task_page:1,
        get_task_limit:10,
        get_task_time:'',
        get_task_ketword:'',
        get_task_add_time:'',
    },
    setTabIndex(e) {
      console.log("onload")

        this.setData({
            tabIndex: e.currentTarget.dataset.index
        })
    },
    goPage(event) {
      console.log("onload")
        if (event.currentTarget.dataset.pageurl == "/pages/register/register") {
            Toast('暂未开放注册~');
        }
        wx.navigateTo({
            url: event.currentTarget.dataset.pageurl,
        })
    },
    onLoad() {
      var that = this
      // request.requestAjax('userinfo', {}, "加载中", function(res) {
      //   if (res.status == 200) {
      //       that.setData({
      //           userinfo:res.data,
      //           user_roles:that.data.roleslist[res.data.role]
      //       });
      //       that.tosel()
      //       return false;
      //   } else {
      //       wx.showToast({
      //           title: '请求失败',
      //           icon: "none"
      //       })
      //   }
      // }, function(res) {
      //     wx.showToast({
      //         title: '请求失败',
      //         icon: "none"
      //     })
      // });
    },
    onShow() {
      console.log("onshow")
      var that = this
      this.tosel()
    },
    onReady() {

    },
    beforeGoPage(e) {
        var type = e.currentTarget.dataset.type;
        var index = e.currentTarget.dataset.index;
        var data = this.data.accounts[type][index];
        var jumpParam = {
            currentTarget: {
                dataset: {
                    pageurl: "/pages/accountinfo/accountinfo?id=" + data.id
                }
            }
        }


        if (data.sub_type == 4 || data.sub_type) {
            if (data.sub_type == 4) {
                //应收
                jumpParam = {
                    currentTarget: {
                        dataset: {
                            pageurl: "/pages/receivable/receivable?id=" + data.id + '&type=1'
                        }
                    }
                }
            }
            if (data.sub_type == 5) {
                //应付
                jumpParam = {
                    currentTarget: {
                        dataset: {
                            pageurl: "/pages/receivable/receivable?id=" + data.id + '&type=2'
                        }
                    }
                }
            }

        }
        this.goPage(jumpParam)
    },
    goPage(event) {
        if (event.currentTarget.dataset.pageurl == "/pages/register/register") {
            Toast('暂未开放注册~');
            return false;
        }

        wx.navigateTo({
            url: event.currentTarget.dataset.pageurl,
        })

    },

    todingdan(event) {
        wx.navigateTo({ url: '/pages/add_dingdan/add_dingdan' })
    },


    dingdanlist(event) {
        wx.navigateTo({ url: '/pages/dingdanList/dingdanList' })
    },

    shengchan(event) {
        wx.navigateTo({ url: '/pages/shengchan/shengchan' })
    },

    bianjidingdan(event) {
        wx.navigateTo({ url: '/pages/addinfo/addinfo' })
    },

    wanshandingdna(event) {
        wx.navigateTo({ url: '/pages/wanshandingdna/wanshandingdna' })
    },
    kehuinfo(event) {
        wx.navigateTo({ url: '/pages/kehuinfo/kehuinfo' })
    },

    material_list(){
      wx.navigateTo({ url: '/pages/material_list_new/material_list_new' })
    },
    material_management(){
      wx.navigateTo({ url: '/pages/material_management/material_management' })
    },
    pic_no_list(){
      wx.navigateTo({ url: '/pages/pic_no_list/pic_no_list' })
    },
    flow_chart(){
      wx.navigateTo({ url: '/pages/flow_chart/flow_chart' })
    },
    tosel(e){
      console.log(e,"===toseltosel")
      let that = this
      if(e === undefined){
        this.setData({
          selstart:0
        })
      }else{
        this.setData({
          selstart:Number(e)
        })
      }
      if(this.data.selstart === 0){
        let tmp = {
          page:this.data.get_task_page,
          limit:this.data.get_task_limit,
          add_time:this.data.get_task_add_time,
          keyword:this.data.get_task_ketword,
        }
        console.log(tmp,"get_task_ketword")
        request.requestGet('order/get_task_list', tmp, "加载中",function (res) {
          console.log(res,"====res")
            if (res.status === 200) {
              
              that.setData({
                list: res.data,
              })
            }
          }, function (res) {
            console.log(res,"请求失败")
          },
        )
      }
      // request.requestGet('get_todo_list', {}, '正在加载',function (res) {
      //   if (res.status === 200) {
      //     that.setData({
      //       data1:res.data.data1,
      //       data2:res.data.data2,
      //       data3:res.data.data3,
      //       data4:res.data.data4,
      //       data5:res.data.data5,
      //     })
      //     if(that.data.selstart === 1){
      //       that.setData({
      //         data1:that.data.data1,
      //         worklist:that.data.data1,
      //       });
      //     }else if(that.data.selstart === 2){
      //       that.setData({
      //         data2:that.data.data2,
      //         worklist:that.data.data2,

      //       });
      //     }else if(that.data.selstart === 3){
      //       that.setData({
      //         data3:that.data.data3,
      //         worklist:that.data.data3,

      //       });
      //     }else if(that.data.selstart === 4){
      //       that.setData({
      //         data4:that.data.data4,
      //         worklist:that.data.data4,

      //       });
      //     }else if(that.data.selstart === 5){
      //       that.setData({
      //         data5:that.data.data5,
      //         worklist:that.data.data5,
      //       });
      //     }
      //   }else{
      //     wx.showToast({
      //       title: res.msg,
      //       icon:'none'
      //     })
      //   }
      // }, function (res) {
      //   wx.showToast({
      //     title: '加载失败',
      //     icon:'none'
      //   })
      // })
    },

    quality_testing(e){
      let id = e.currentTarget.dataset.index
      this.data.selstart = 1
      wx.navigateTo({ url: `/pages/quality_testing/quality_testing?id=${id}` })
    },

    new_look_purchase_orders(e){
      this.data.selstart = 4
      let id = e.currentTarget.dataset.index
      wx.navigateTo({ url: `/pages/look_purchase_orders/look_purchase_orders?id=${id}` })
    },

    go_new_look_purchase_orders(e){
      let id = e.currentTarget.dataset.index
      wx.navigateTo({ url: `/pages/new_look_purchase_orders/new_look_purchase_orders` })
    },

    handle_invalid(e){
      let id = e.currentTarget.dataset.index
      this.data.selstart = 5
      wx.navigateTo({ url: `/pages/handle_invalid/handle_invalid?id=${id}` })
    },

    setgocome(e){
      let id = e.currentTarget.dataset.index
      this.data.selstart = 3
      wx.navigateTo({  url: `/pages/setgocome/setgocome?id=${id}` })
    },

    delivery_warning(e){
        let p_no = e.currentTarget.dataset.index
        this.data.selstart = 2
        wx.navigateTo({  url: `/pages/to_delivery/to_delivery?p_no=${p_no}` })
    },
    tmpfunction(){
      let tmp = 4
      wx.navigateTo({  url: `/pages/production_record/production_record?id=${tmp}` })
    },
    flow_chart(e){
      let tmpid = e.currentTarget.dataset.id
      wx.navigateTo({ url: `/pages/flow_chart/flow_chart` })
    },

    onTabChange(event){
      this.setData({
        activeTab:event.detail.index
      })
      this.tosel(this.data.activeTab,"activeTabactiveTab")
    },

    scanCode(e){
      console.log(e,"用户点击扫码")
      wx.scanCode({
        onlyFromCamera: false, // 允许从相册选择
        scanType: ['qrCode'],  // 仅识别二维码
        success: (res) => {
          console.log(res,"成功")
          console.log(res.result,"成功")
          const url = res.result; // 获取二维码内容
          let tmpinfo = res.result
          let tmplist
          tmplist = tmpinfo.split('?id=')
          if(tmplist[1] === undefined || tmplist[1] === null){
            wx.showToast({
              title: '二维码不符合规则',
              icon: 'none',
              duration: 1000  // 2秒后自动关闭
            })
            return false
          }
          let tmpid = tmplist[1]
          wx.navigateTo({
            url: `/pages/flow_chart/flow_chart?id=${tmpid}`
          });
        },
        fail: (err) => {
          console.log(err,"失败")
          wx.showToast({ title: '扫码失败', icon: 'none' });
        }
      });
    },
    lanya(){
      let self = this
      wx.openBluetoothAdapter({
        success: function (res) {
          self.setData({
            connState: true,
            blueLists: [],
            searchState: false,
            connDevice: '',
            connectInit: false,
            WH: [0, 0]
          })
        },
        fail: function (res) {
          if (res.errMsg === 'openBluetoothAdapter:fail already opened') {
            self.setData({
              connState: true,
              blueLists: [],
              searchState: false,
              connDevice: '',
              connectInit: false,
              WH: [0, 0]
            })
            return
          }
          console.log('openBluetoothAdapter', res)
          self.setData({
            connState: false
          })
          wx.showToast({
            title: '请先打开蓝牙功能',
            icon: 'none',
            duration: 2000,
            mask: true
          })
        },
        complete() {
          self.blueSearch()
        }
      })
    },

  /*停止扫描*/
  blueUnsearch: function () {
    let self = this
    console.log('停止扫描')
    return new Promise((reslove) => {
      wx.stopBluetoothDevicesDiscovery({
        success: function (res) {
          self.setData({
            searchState: false
          })
          reslove(res)
        },
        fail: function (res) {
          console.log('stopBluetoothDevicesDiscovery', res)
        }
      })
    })

  },

  /*测试*/
  testPrint: function (e) {

    console.log(e,"测试")

    // ~JA(复位) ^XA~^XZ(头尾) ^FO(文本位置) ^LL(连续纸定义长度y) ^FD(文本内容)^FS
    let str = "~JA^XA" + "^FO0,0" + "^LL10^FD ^FS" + "^XZ"
    let buffer = this.textchange(str, 'text')
    for (var j = 0; j < buffer.byteLength; j += 20) {
      this.writeBle(e, buffer.slice(j, j + 20))
    }
  },
  

  textPrint: function (e) {
    //~JA(复位) ^XA~^XZ(头尾) ^CI(编码-中文26) ^LL(连续纸定义长度y) ^LH(起始位置xy) ^FO(文本位置xy) ^A(字体A~Z/0~9,旋转NRIB-0-90-180-270,字高,字宽)
    //let str = "~JA^XA" + "^CI26^LL50" + "^LH0,0^FO0,10^A0N,30,30^FD测试文本ABC^FS" + "^XZ"

    let str = "~JA^XA^CI26^LL1000^PW700^LH0,0^FO20,20^A0N,28,28^FD 测试名称 ^FS^FO390,20^A0N,28,28^FD 2022-08-31 ^FS^FO250,70^A0N,28,28^FD 0 箱 ^FS^FO20,110" + "^BCN,70,Y,N,N" + "^FD CS141414145454 ^FS^FO500,200^A0N,20,20^FD 入仓标 ^FS^XZ";

    let buffer = this.textchange(str, 'text')
    for (var j = 0; j < buffer.byteLength; j += 20) {
      this.writeBle(e, buffer.slice(j, j + 20))
    }
  },

   /*条码*/
   codePrint: function (e) {
    //~JA(复位) ^XA~^XZ(头尾) ^FOx,y(文本位置) ^BC(Code 128条码,字体旋转NRIB-0-90-180-270,高度,注释行YN-打印-不打印,注释行位置NY-下方-上方,校验位NY-不打印-打印) ^LL(连续纸定义长度y) ^FD(文本内容)^FS
    let strA = "~JA^XA" + "^FO0,0" + "^BCN,100,Y,N,N" + "^LL150^FDTEST1234^FS" + "^XZ"
    let bufferA = this.textchange(strA, 'text')
    for (var i = 0; i < bufferA.byteLength; i += 20) {
      this.writeBle(e, bufferA.slice(i, i + 20))
    }

    //~JA(复位) ^XA~^XZ(头尾) ^FOx,y(文本位置) ^BQ(二维码,模型2-1-默认-其它,放大倍数) ^LL(连续纸定义长度y) ^FD(纠错HQML-默认Q|输入AM-自动-手动,文本内容)^FS
    let strB = "~JA^XA" + "^FO0,0" + "^BQ,2,10" + "^LL300^FDLA,TEST-1234 3D code^FS" + "^XZ"
    let bufferB = this.textchange(strB, 'text')
    for (var j = 0; j < bufferB.byteLength; j += 20) {
      this.writeBle(e, bufferB.slice(j, j + 20))
    }
  },

  textchange: function (e, changetype) {
    if (changetype == 'text') {
      //字符串转gb2312
      return new encoding.TextEncoder("gb2312", {
        NONSTANDARD_allowLegacyEncoding: true
      }).encode(e).buffer
    } else if (changetype == 'image') {
      //RGB数组转黑白数组
      let imageor = []
      let ints = Array.from(e)
      console.log("黑白之前")
      console.log(ints)
      for (var i = 0, j = 0; i < ints.length; i = i + 4, j++) {
        imageor[j] = (ints[i] * 0.299 + ints[i + 1] * 0.587 + ints[i + 2] * 0.144) > 170 ? 0 : 1
      }
      //黑白数组转16进制数组
      let image = []
      let temp = 0
      //let WH = this.data.WH
      console.log("黑白之后")
      console.log(imageor);
      for (var j = 0; j < imageor.length / 8; j++) {
        image[j] = imageor[temp] + "" + imageor[temp + 1] + "" + imageor[temp + 2] + "" + imageor[temp + 3] + "" + imageor[temp + 4] + "" + imageor[temp + 5] + "" + imageor[temp + 6] + "" + imageor[temp + 7]
        temp += 8
        image[j] = bin_to_hex(image[j]);

      }
      return image
    }
    //二进制转十六进制
    function bin_to_hex(str) {
      let hex_array = [{
        key: 0,
        val: "0000"
      }, {
        key: 1,
        val: "0001"
      }, {
        key: 2,
        val: "0010"
      }, {
        key: 3,
        val: "0011"
      }, {
        key: 4,
        val: "0100"
      }, {
        key: 5,
        val: "0101"
      }, {
        key: 6,
        val: "0110"
      }, {
        key: 7,
        val: "0111"
      }, {
        key: 8,
        val: "1000"
      }, {
        key: 9,
        val: "1001"
      }, {
        key: 'a',
        val: "1010"
      }, {
        key: 'b',
        val: "1011"
      }, {
        key: 'c',
        val: "1100"
      }, {
        key: 'd',
        val: "1101"
      }, {
        key: 'e',
        val: "1110"
      }, {
        key: 'f',
        val: "1111"
      }]
      let value = ''
      let list = []
      if (str.length % 4 !== 0) {
        let a = "0000"
        let b = a.substring(0, 4 - str.length % 4)
        str = b.concat(str)
      }
      while (str.length > 4) {
        list.push(str.substring(0, 4))
        str = str.substring(4);
      }
      list.push(str)
      for (let i = 0; i < list.length; i++) {
        for (let j = 0; j < hex_array.length; j++) {
          if (list[i] == hex_array[j].val) {
            value = value.concat(hex_array[j].key)
            break
          }
        }
      }
      return value
    }
  },

  /*传图*/
  imageUpload: function (e) {
    var self = this
    self.imagePrint(e)

    // var self = this
    // var image = {};
    // wx.getImageInfo({
    //   src: "https://s1.ax1x.com/2022/08/18/vDjnVU.jpg",
    //   success(res) {
    //     image = res.path
    //     self.setData({
    //       WH: [720, 720]
    //     })
    //   },
    //   complete: function () {
    //     var WH = self.data.WH
    //     //画图
    //     const ctx = wx.createCanvasContext('myCanvas')
    //     ctx.drawImage(image, 0, 0, WH[0], WH[1])
    //     // ctx.drawImage(res.tempFilePaths[0], 0, 0, WH[0], WH[1])
    //     ctx.draw()
    //     setTimeout(function () {
    //       self.imagePrint(e)
    //     }, 500)
    //   }
    // })
  },

  /*写入*/
  writeBle: function (e, buffer) {
    console.log("buffer", e, buffer);
    wx.writeBLECharacteristicValue({
      deviceId: e[0],
      serviceId: e[1],
      characteristicId: e[2],
      value: buffer,
      success: function (res) {
        console.log('测试写入成功', res)
      },
      fail: function (res) {
        console.log('测试写入失败', res)
      }
    })
  },

  /*条码*/
  codePrint: function (e) {
    //~JA(复位) ^XA~^XZ(头尾) ^FOx,y(文本位置) ^BC(Code 128条码,字体旋转NRIB-0-90-180-270,高度,注释行YN-打印-不打印,注释行位置NY-下方-上方,校验位NY-不打印-打印) ^LL(连续纸定义长度y) ^FD(文本内容)^FS
    let strA = "~JA^XA" + "^FO0,0" + "^BCN,100,Y,N,N" + "^LL150^FDTEST1234^FS" + "^XZ"
    let bufferA = this.textchange(strA, 'text')
    for (var i = 0; i < bufferA.byteLength; i += 20) {
      this.writeBle(e, bufferA.slice(i, i + 20))
    }

    //~JA(复位) ^XA~^XZ(头尾) ^FOx,y(文本位置) ^BQ(二维码,模型2-1-默认-其它,放大倍数) ^LL(连续纸定义长度y) ^FD(纠错HQML-默认Q|输入AM-自动-手动,文本内容)^FS
    let strB = "~JA^XA" + "^FO0,0" + "^BQ,2,10" + "^LL300^FDLA,TEST-1234 3D code^FS" + "^XZ"
    let bufferB = this.textchange(strB, 'text')
    for (var j = 0; j < bufferB.byteLength; j += 20) {
      this.writeBle(e, bufferB.slice(j, j + 20))
    }
  },

   /* Demo票据 */
   typePrint: function (e, did) {
    var self = this
    switch (did) {
      case '停车场小票':
        var str = "~JA^XA" + "^CI26^LL440" + "^LH0,0"
        str += "^FO205,5^A0N,28,28^FD停车场小票^FS"
        str += "^FO165,40" + "^BCN,70,Y,N,N" + "^FDTEST123^FS"
        str += "^FO0,150^A0N,23,23^FD编号: 20181210120083^FS"
        str += "^FO0,190^A0N,23,23^FD车牌号: 粤J.00000^FS"
        str += "^FO0,220^A0N,23,23^FD进门时间: 2018 - 12 - 10 12: 09^FS"
        str += "^FO0,250^A0N,23,23^FD车类: 小轿车^FS"
        str += "^FO0,280^A0N,23,23^FD操作员: 张三^FS"
        str += "^FO0,310^A0N,23,23^FD联系电话: 13800138000^FS"
        str += "^FO0,340^A0N,23,23^FD重要提示^FS"
        str += "^FO0,370^A0N,23,23^FD1.离开时凭小票换取发票^FS"
        str += "^FO0,400^A0N,23,23^FD2.车辆停放时不负担看管责任^FS" + "^XZ"
        var buffer = this.textchange(str, 'text')
        for (var j = 0; j < buffer.byteLength; j += 20) {
          this.writeBle(e, buffer.slice(j, j + 20))
        }
        break
      case '美团外卖小票':
        var str = "~JA^XA" + "^CI26^LL520" + "^LH0,0"
        str += "^FO195,0^A0N,28,28^FD美团外卖小票^FS"
        str += "^FO0,35^A0N,25,25^FD【已在线支付】^FS"
        str += "^FO0,65^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,95^A0N,23,23^FD下单时间：2018-12-10 16:56^FS"
        str += "^FO0,123^A0N,23,23^FD订单编号：201812101656^FS"
        str += "^FO0,151^A0N,25,25^FD- - - - - - - - - - - - - - - - - - 菜品 - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,181^A0N,23,23^FD香辣鸡腿堡                       X1                       ￥20.00^FS"
        str += "^FO0,209^A0N,23,23^FD大薯条                             X1                       ￥15.00^FS"
        str += "^FO0,237^A0N,23,23^FD百事可乐（中）                X1                      ￥10.00^FS"
        str += "^FO0,265^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,295^A0N,23,23^FD配送费：￥5.00^FS"
        str += "^FO0,323^A0N,23,23^FD餐盒费：￥0.00^FS"
        str += "^FO0,351^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,381^A0N,23,23^FD实付                                                             ￥50.00^FS"
        str += "^FO0,409^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,439^A0N,23,23^FD地址：九龙广播道81号亚洲电视台^FS"
        str += "^FO110,480^A0N,25,25^FD************完************^FS" + "^XZ"
        var buffer = this.textchange(str, 'text')
        for (var j = 0; j < buffer.byteLength; j += 20) {
          this.writeBle(e, buffer.slice(j, j + 20))
        }
        break
      case '交警罚单小票':
        var str = "~JA^XA" + "^CI26^LL400" + "^LH0,0"
        str += "^FO195,0^A0N,28,28^FD市区罚款单^FS"
        str += "^FO0,40^A0N,23,23^FDNO.20181210120083^FS"
        str += "^FO0,65^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,90^A0N,23,23^FD发证机关：某公安局^FS"
        str += "^FO0,115^A0N,23,23^FD车辆牌号：粤J.00000^FS"
        str += "^FO0,140^A0N,23,23^FD车辆类型：小型轿车^FS"
        str += "^FO0,165^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS"
        str += "^FO0,190^A0N,23,23^FD违法时间：2018-12-10 12:09^FS"
        str += "^FO0,215^A0N,23,23^FD违法地址：九龙广播道^FS"
        str += "^FO0,240^A0N,23,23^FD罚款金额：100元^FS"
        str += "^FO0,270^A0N,23,23^FD  请您于15日内到指定派出所违法处理大厅（地址：某^FS"
        str += "^FO0,295^A0N,23,23^FD某路某某楼XX号 电话：13800138000），接受处理^FS"
        str += "^FO0,320^A0N,23,23^FD备注：机动车所有人联系方式发生变化时，请及时到所^FS"
        str += "^FO0,345^A0N,23,23^FD属派出所进行处理^FS"
        str += "^FO0,370^A0N,25,25^FD- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -^FS" + "^XZ"
        var buffer = this.textchange(str, 'text')
        for (var j = 0; j < buffer.byteLength; j += 20) {
          this.writeBle(e, buffer.slice(j, j + 20))
        }
        break
      case '打印处方':
        var str = "~JA^XA" + "^CI26^LL380" + "^LH0,0"
        str += "^FO195,5^A0N,28,28^FD某某大医院^FS"
        str += "^FO175,35^A0N,28,28^FD儿科门诊处方单^FS"
        str += "^FO0,70^A0N,23,23^FD处方编号:9699695959^FS"
        str += "^FO0,95^A0N,23,23^FD处方日期:2018-12-10 12:09^FS"
        str += "^FO0,120^A0N,23,23^FD主诊医生：王五^FS"
        str += "^FO0,145^A0N,23,23^FD广州白云山星群夏桑菊                                       2包^FS"
        str += "^FO215,170^A0N,23,23^FD每日3次/1次1包       批号:1010110^FS"
        str += "^FO0,195^A0N,23,23^FD羚锐解毒散结胶囊                                            3盒^FS"
        str += "^FO215,220^A0N,23,23^FD每日3次/1次2粒       批号:1010550^FS" + "^XZ"
        var buffer = this.textchange(str, 'text')
        for (var j = 0; j < buffer.byteLength; j += 20) {
          this.writeBle(e, buffer.slice(j, j + 20))
        }
        break
    }
  },





  tolanya(){
    wx.navigateTo({ url: '/pages/tolanya/tolanya' })
  },


  onSearch(e){
    this.setData({
      flag:true
    })
    this.data.page = 1
    this.data.datafind = e.detail
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
    this.getList(e.detail)
  },

  
})

